Dashboard Temp Share Shortlinks Frames API

HTMLify

Non-Repeating Element.cpp
Views: 1 | Author: cody
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class Solution{
    public:
    int firstNonRepeating(int arr[], int n) 
    { 
        // Complete the function
        map<int,int>mpp;
        
        for(int i =0; i<n; i++){
                mpp[arr[i]]++;
        }
        for(int i=0; i<n; i++){
            if(mpp[arr[i]] == 1) return arr[i];
            
        }
        return -1;
    } 
  
};